﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Org.Mentalis.Proxy.Http;

namespace Demo
{
    public partial class Form1 : Form
    {
        public List<string> cache = new List<string>();
        public bool ProxyStart = false;
        public HttpListener httpListener = new HttpListener(98);
        public Timer Timer = new Timer();
        public Form1()
        {
            InitializeComponent();
            listView1.FullRowSelect = true;
            listView1.View = View.Details;
            listView1.Columns.Add(new ColumnHeader() { Text = "请求", Width = 430 });
            httpListener.OnProcessQuery += (text) => {
                cache.Add(text);
            };
            listView1.Click += (a,v) => {
                Clipboard.SetText(listView1.SelectedItems[0].Text);
            
            };
            Timer.Interval = 10;
            Timer.Tick += (e,d) => {
                if (cache.Count > 0) {
                    for (int i=0;i<cache.Count;i++) {
                        listView1.Items.Add(cache[i]);
                    }
                    cache.Clear();
                }
            };
            Timer.Start();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (!httpListener.Listening)
            {
                httpListener.Start();
                Timer.Start();
                button1.Text = "关闭代理服务器";
            }
            else {
                Timer.Stop();
                httpListener.Dispose();
                button1.Text = "开启代理服务器";
            }
        }
    }
}
